package list;

import interfaces.IStack;

public class SLListStack implements IStack {
	

	Node head;
	Node tail;
	int n;
	
	
	

	public SLListStack() {
		this.head = null;
		this.tail = null;
		this.n = 0;
	}



	@Override
	public boolean push(String x) {
		
		Node node = new Node();
		node.x = x;
		node.next = head;
		head = node;
		if(n == 0) {
			tail = node;
		}
		n++;
		return true;
	}

	@Override
	public String pop() {
		if(n==0){
			throw new NullPointerException();
		}else{
			//continue
		}
		String result = head.x;
		head = head.next;
		if(--n == 0) {
			tail = null;
		}
		return result;
	}

}

